﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Rage
{
    public static class BaseStats
    {
        // Only returns level 50 characters.
        #region Cache Variables
        // Caching to reduce load.
        private static Stats _lastStats;
        private static int _lastLevel;
        private static CharacterClass _lastClass;
        private static CharacterRace _lastRace;
        private static readonly object syncLock = new object();
        #endregion

        public static Stats GetBaseStats(Character character) { return GetBaseStats(character.Level, character.Class, character.Race); }
        public static Stats GetBaseStats(int level, CharacterClass characterClass, CharacterRace characterRace)
        {   // Health, Mana and some other things are same for every race.
            lock (syncLock)
            {
                #region Cache
                if (level == _lastLevel
                    && characterClass == _lastClass
                    && characterRace == _lastRace)
                    return _lastStats.Clone();
                _lastLevel = level;
                _lastClass = characterClass;
                _lastRace = characterRace;
                #endregion

                Stats S = new Stats();
                #region Race, not class benefit
                // Most Level 85 Race and Class Stats come from:
                // http://code.google.com/p/simulationcraft/source/browse/branches/cataclysm/engine/sc_rating.cpp?r=6207
                // When they were still at 80 as of Jan 01st, 2011

                // From SimCraft
                Stats race = new Stats();
                switch (characterRace)
                {
                    // Alliance
                    default: break;
                    //case CharacterRace.Human:    race.Strength = 20; race.Cunning = 20; race.Endurance = 20; race.Willpower = 20; race.Aim = 20; break;
                    //case CharacterRace.Dwarf:    race.Strength = 25; race.Agility = 16; race.Stamina = 21; race.Intellect = 19; race.Spirit = 19; break;
                    //case CharacterRace.NightElf: race.Strength = 16; race.Agility = 24; race.Stamina = 20; race.Intellect = 20; race.Spirit = 20; break;
                    //case CharacterRace.Gnome:    race.Strength = 15; race.Agility = 22; race.Stamina = 20; race.Intellect = 24; race.Spirit = 20; break;
                    //case CharacterRace.Draenei:  race.Strength = 21; race.Agility = 17; race.Stamina = 20; race.Intellect = 20; race.Spirit = 22; break;
                    //case CharacterRace.Worgen:   race.Strength = 23; race.Agility = 22; race.Stamina = 20; race.Intellect = 16; race.Spirit = 19; break;
                    // Horde
                    //case CharacterRace.Orc:      race.Strength = 23; race.Agility = 17; race.Stamina = 21; race.Intellect = 17; race.Spirit = 22; break;
                    //case CharacterRace.Undead:   race.Strength = 19; race.Agility = 18; race.Stamina = 20; race.Intellect = 18; race.Spirit = 25; break;
                    //case CharacterRace.Tauren:   race.Strength = 25; race.Agility = 16; race.Stamina = 21; race.Intellect = 16; race.Spirit = 22; break;
                    //case CharacterRace.Troll:    race.Strength = 21; race.Agility = 22; race.Stamina = 20; race.Intellect = 16; race.Spirit = 21; break;
                    //case CharacterRace.BloodElf: race.Strength = 17; race.Agility = 22; race.Stamina = 20; race.Intellect = 23; race.Spirit = 18; break;
                    //case CharacterRace.Goblin:   race.Strength = 17; race.Agility = 22; race.Stamina = 20; race.Intellect = 23; race.Spirit = 20; break;
                    //default: { break; }
                };
                // From Chardev (85)
                //Class           Str Agi Sta Int Spi
                //Druid            76  69  86 136 153
                //Shaman          111  60 128 119 136
                //Death Knight    171 101 154  16  44
                //Hunter           60 178 119  77  88
                //Mage             17  26  43 187 175
                //Paladin         144  77 136  86  97
                //Priest           26  34  51 188 183
                //Rogue           102 186  94  26  53
                //Warlock          43  51  76 161 166
                //Warrior         169 103 153  17  44
                #endregion

                #region Base Stats
                #region All Classes
                S.Miss  = 0.10f;
                S.Dodge = 0.04f;
                S.Shield = 0.00f;
                S.Parry = 0.04f;
                S.BonusCritChance = 0.05f;
                #endregion
                switch (characterClass)
                {
                    case CharacterClass.Gunslinger:
                    case CharacterClass.Scoundrel:
                    case CharacterClass.Operative:
                    case CharacterClass.Sniper: {
                        Stats s = new Stats() { Strength = 50, Aim = 100, Endurance = 225, Cunning = 250, Willpower = 50, Presence = 225, Health = 2500, };
                        S.Accumulate(race);
                        S.Accumulate(s);
                        break;
                    }
                    case CharacterClass.Powertech:
                    case CharacterClass.Mercenary:
                    case CharacterClass.Vanguard:
                    case CharacterClass.Commando: {
                        Stats s = new Stats() { Strength = 50, Aim = 250, Endurance = 225, Cunning = 100, Willpower = 50, Presence = 225, Health = 2500, };
                        S.Accumulate(race);
                        S.Accumulate(s);
                        break;
                    }
                    case CharacterClass.Guardian:
                    case CharacterClass.Sentinel:
                    case CharacterClass.Juggernaut:
                    case CharacterClass.Marauder: {
                        Stats s = new Stats() { Strength = 250, Aim = 50, Endurance = 225, Cunning = 50, Willpower = 100, Presence = 225, Health = 2500, };
                        S.Accumulate(race);
                        S.Accumulate(s);
                        break;
                    }
                    case CharacterClass.Assassin:
                    case CharacterClass.Sorcerer:
                    case CharacterClass.Sage:
                    case CharacterClass.Shadow: {
                        Stats s = new Stats() { Strength = 100, Aim = 50, Endurance = 225, Cunning = 50, Willpower = 250, Presence = 225, Health = 2500, };
                        S.Accumulate(race);
                        S.Accumulate(s);
                        break;
                    }
                    #region No Class
                    default:
                        break;
                    #endregion
                }
                #endregion

                _lastStats = S.Clone();
                return S;
            }
        }
    }
}
